package com.wangxi.boot9reg.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
public class UploadController {
    @RequestMapping("/upload")
    public String upload(MultipartFile picFile) throws IOException {
        String file = picFile.getOriginalFilename();
        String filePath = file.substring(file.lastIndexOf("."));
        String fileName = UUID.randomUUID()+filePath;
        String dirPath = "D:/files";
        File dirFile = new File(dirPath);
        if(!dirFile.exists()){
            dirFile.mkdirs();
        }
        picFile.transferTo(new File(dirPath+"/"+fileName));
        System.out.println("已存入!");
        return fileName;
    }
    @RequestMapping("/deletePic")
    public void deletePic(String name){
        String dirPath = "D:/files";
        new File(dirPath+"/"+name).delete();
    }
}
